#include <header.h>
int main(int argc, char* argv[]){
	ARGS_CHECK(argc, 1);

	char *port = "8080";
	char *ip = "192.168.169.128";
	int socket_fd = socket(AF_INET, SOCK_STREAM, 0);
	ERROR_CHECK(socket_fd, -1, "socket");

	struct sockaddr_in serveraddr;
	serveraddr.sin_family = AF_INET;
	serveraddr.sin_port = htons(atoi(port));
	serveraddr.sin_addr.s_addr = inet_addr(ip);
	bind(socket_fd, (struct sockaddr*)&serveraddr, sizeof serveraddr);

	int ret1 = listen(socket_fd, 10);
	ERROR_CHECK(ret1, -1, "listen");


	// 阻塞函数,哪里有问题？
	int socket_fd_new = accept(socket_fd, NULL, NULL);
	ERROR_CHECK(socket_fd_new, -1, "accept");


	while(1){
		// read from socket
		char buf[1 << 10] = {0};
		recv(socket_fd_new, buf, sizeof buf, 0);
		printf("clent:%s\n", buf);

		__bzero(buf, sizeof buf);
		read(STDIN_FILENO, buf, sizeof buf);
		send(socket_fd_new, buf, sizeof buf, 0);

	}

	close(socket_fd_new);
	close(socket_fd);
	return 0;
}